import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gcglobal/HomePage/GCTabbarPageView.dart';
import 'package:gcglobal/HomePage/HomePageView.dart';
import 'package:gcglobal/HomePage/RecordList/GCInvoiceRecordPageView.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sp_util/sp_util.dart';
import 'loginView/loginPage.dart';

import 'package:easy_localization/easy_localization.dart';


void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();
  await SpUtil.getInstance();
  SharedPreferences preferences = await SharedPreferences.getInstance();
  runApp(

    EasyLocalization(
        supportedLocales: [Locale('en'), Locale('en-ch')],
        path: 'assets/translations', // <-- change the path of the translation files
        fallbackLocale: Locale('en', 'ch'),
        child: MyApp(preferences.getString("sk"))
    ),
  );


  configLoading();

}
void configLoading() {
  print("--------");
  EasyLoading.instance
    ..displayDuration = const Duration(milliseconds: 2000)
    ..indicatorType = EasyLoadingIndicatorType.fadingCircle
    ..loadingStyle = EasyLoadingStyle.dark
    ..indicatorSize = 45.0
    ..radius = 10.0
    ..progressColor = Colors.yellow
    ..backgroundColor = Colors.green
    ..indicatorColor = Colors.yellow
    ..textColor = Colors.yellow
    ..maskColor = Colors.blue.withOpacity(0.5)
    ..userInteractions = true
    ..dismissOnTap = false;
}
class MyApp extends StatefulWidget {
  String? sessionkey;
  MyApp(this.sessionkey);
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return MyAppState();
  }
  // This widget is the root of your application.
}
class MyAppState extends State<MyApp>{
  @override
  void dispose() {
    // TODO: implement dispose

    super.dispose();
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: Size(750,1624),
        builder: (context,child){
          return MaterialApp(
            title: 'GCGlobal',
            theme: ThemeData(

              primarySwatch: Colors.blue,
            ),
            routes: {
              '/TabbarPageView': (BuildContext context) => GCTabbarPageView(),
              '/HomePage':(BuildContext context) => HomePageView()
            },
            builder: EasyLoading.init(),
            home: (widget.sessionkey==null||widget.sessionkey!.length<=0)?loginPage(): GCTabbarPageView(),
            localizationsDelegates: context.localizationDelegates,
            supportedLocales: [
              Locale('en'),
              Locale('en-ch'),
            ],

            locale: Locale('ch'),
          );
        });
  }

}

